<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
	height="30" horizontalGap="2" verticalAlign="middle"
	fontSize="10">


	<mx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;

			[Bindable] public var searchLabel:String = "Search";
			[Bindable] public var optionsLabels:ArrayCollection = null;
			[Bindable] public var optionsFields:ArrayCollection= null;			
			
			
			public function clearUI():void{
				searchInput.text = "";
				combo.selectedIndex = 0;
			}
			
			private function clear():void{
				clearUI();
				search();
			}
			
			private function search():void{
				var text:String = this.getFormattedString(searchInput.text);
				var aEvent:SearchEvent = new SearchEvent(SearchEvent.EVENT_NAME);
				aEvent.filterFields = getFields();
				aEvent.filterText = text;
				dispatchEvent(aEvent);
			}
			
			private function getFormattedString(str:String):String{
				if (str == ""){
					str = null;
				}
				return str;
			}
			
			private function getFields():Array{
				var fields:ArrayCollection = new ArrayCollection();
				var array:Array = optionsFields.getItemAt(combo.selectedIndex) as Array;
				return array;
			}
			
		]]>
	</mx:Script>

	<mx:Metadata>
		[Event(name="search", type="main.br.org.indt.ndg.ui.component.powerdatagrid.SearchEvent")]
	</mx:Metadata>
	

	<mx:Label text="{searchLabel}" fontWeight="bold"/>
	<mx:TextInput id="searchInput" enter="search()" height="22"/>
	<mx:ComboBox id="combo" dataProvider="{optionsLabels}" height="22" styleName="paginationCombo"/>
	<mx:Button click="search()" styleName="iconButton" width="22" height="22">
		<mx:icon>@Embed(source='../../../../../../../resources/images/SEARCH_TRANSP.png')</mx:icon>
	</mx:Button>
	<mx:Button click="clear()" styleName="iconButton" width="22" height="22">
		<mx:icon>@Embed(source='../../../../../../../resources/images/CLEAR_TRANSP.png')</mx:icon>
	</mx:Button>
	
</mx:HBox>
